package net.sourceforge.zbar.android;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.ums.upos.uapi.R;


public class CustDialog  extends Dialog implements View.OnClickListener{

	private TextView dialog_content, dialog_title;
	private Button dialog_cancle, dialog_confirm;
	private CallBackListener mCall;
	public static final int ACTION_CANCLE=-1;
	public static final int ACTION_CONFIRM=1;
	
	
	private String strTag;
	
	private  Object target;
	
	
	
	public Object getTarget() {
		return target;
	}

	public void setTarget(Object target) {
		this.target = target;
	}

	public String getStrTag() {
		return strTag;
	}

	public void setStrTag(String strTag) {
		this.strTag = strTag;
	}

	public void setContentTextSize(float size){
		if(size>0){
			dialog_content.setTextSize(size);
		}
	}
	
	public void setConfirmText(String text){
		if(!TextUtils.isEmpty(text)){
			dialog_confirm.setText(text);
		}
	}
	
	public void setCancleText(String text){
		if(!TextUtils.isEmpty(text)){
			dialog_cancle.setText(text);
		}
	}
	
	
	public CustDialog(Context context, int theme) {
		super(context, theme);
		intital();
	}
	
	public CustDialog(Context context) {
		super(context, R.style.c_style_dialog);
		intital();
	}
	
	@Override
	public void onDetachedFromWindow() {
		super.onDetachedFromWindow();
		
	}

	
	public void setCallBackListener(CallBackListener call){
		this.mCall=call;
	}

	
	public void setDialogTitle(String title){
		dialog_title.setText(title);
	}
	
	public void setDialogContent(String content){
		dialog_content.setText(content);
	}
	
	private void intital(){
		this.setContentView(R.layout.c_layout_dialog);
		dialog_content = (TextView)findViewById(R.id.dialog_content);
		dialog_title = (TextView)findViewById(R.id.dialog_title);
		
		dialog_cancle = (Button) findViewById(R.id.dialog_cancle);
		dialog_confirm = (Button)findViewById(R.id.dialog_confirm);
		
		dialog_cancle.setOnClickListener(this);
		dialog_confirm.setOnClickListener(this);
	}
	
	public void setOnlyConfirmButton(){
		dialog_cancle.setVisibility(View.GONE);
		findViewById(R.id.divide).setVisibility(View.GONE);
		dialog_confirm.setBackgroundResource(R.drawable.selector_dialog_only);
	
	}
	
	
	public interface CallBackListener{
	
		public void onCallback(View view, int action);
	
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.dialog_cancle:
			this.dismiss();
			if(mCall!=null){
				mCall.onCallback(v, ACTION_CANCLE);
			}

			break;
		case R.id.dialog_confirm:
			this.dismiss();
			if(mCall!=null){
				mCall.onCallback(v, ACTION_CONFIRM);
			}
           
			break;

		default:
			break;
		}
		
	}

}
